﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HomePage.Controllers;
using System.Globalization;
using PortalNews.BUS;
using DataHelper;

namespace TGVR_Project.Controllers
{
    //[Authorize]
    [InitializeSimpleMembership]
    public class UserController : BaseController
    {
        //
        // GET: /User/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult CreateReSale()
        {
            return View();
        }
        [HttpPost]
        public ActionResult CreateReSale(string Title, string Name, string Phone,
                                            string Firm, string FlightNo,
                                            string StationForm, string StationTo, string Date,
                                            int Amount, int Price, string description, string Email
            )
        {
            int iLang = m_lang.iLang;
            m_lang = new Lang(1);
            DateTime dtDatePickerDepartDate = DateTime.ParseExact(Date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            New nViet = new New();
            nViet.Title = Title;
            nViet.Description = string.Format("<div class='re-row'>" +
                            "<div class='re-col'><b>{0}</b>: {1}</div>" +
                            "<div class='re-col'><b>{2}</b>: {3}</div>" +
                        "</div>" +
                        "<div class='re-row'>" +
                            "<div class='re-col'><b>{4}</b>: {5}</div>" +
                            "<div class='re-col'><b>{6}</b>: {7}</div>" +
                        "</div>" +
                        "<div class='re-row'>" +
                            "<div class='re-col'><b>{8}</b>: {9}</div>" +
                            "<div class='re-col'><b>{10}</b>: {11}</div>" +
                        "</div>" +
                        "<div class='re-row'>" +
                            "<div class='re-col'><b>{12}</b>: {13}</div>" +
                            "<div class='re-col'><b>{14}i</b>: {15}</div>" +
                        "</div>" +
                        "<div class='re-row'>" +
                            "<div class='re-col'><b>{16}</b>: {17}</div>" +
                        "</div>"
                        ,
                m_lang.FROMCITY,
                StationForm,
                m_lang.TOCITY,
                StationTo,
                m_lang.FIRM,
                Firm,
                m_lang.FLIGHTNO,
                FlightNo,
                m_lang.DEPARTDATE,
                Date,
                m_lang.PRICE,
                Price.ToString("#,##0"),
                m_lang.NAME,
                Name,
                m_lang.PHONE,
                Phone,
                m_lang.EMAIL,
                Email
                );
            nViet.Content = nViet.Description + string.Format("<div class='re-row'><p>{0}</p></div>", description);
            nViet.CreatedDate = DateTime.Now;
            nViet.UpdatedDate = DateTime.Now;
            nViet.Image = "/Content/Images/Site/logo.jpg";
            nViet.TypeID = 11;


            m_lang = new Lang(2);
            dtDatePickerDepartDate = DateTime.ParseExact(Date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            New nEnglish = new New();
            nEnglish.Title = Title;
            nEnglish.Description = string.Format("<div class='re-row'>" +
                            "<div class='re-col'><b>{0}</b>: {1}</div>" +
                            "<div class='re-col'><b>{2}</b>: {3}</div>" +
                        "</div>" +
                        "<div class='re-row'>" +
                            "<div class='re-col'><b>{4}</b>: {5}</div>" +
                            "<div class='re-col'><b>{6}</b>: {7}</div>" +
                        "</div>" +
                        "<div class='re-row'>" +
                            "<div class='re-col'><b>{8}</b>: {9}</div>" +
                            "<div class='re-col'><b>{10}</b>: {11}</div>" +
                        "</div>" +
                        "<div class='re-row'>" +
                            "<div class='re-col'><b>{12}</b>: {13}</div>" +
                            "<div class='re-col'><b>{14}i</b>: {15}</div>" +
                        "</div>",
                m_lang.FROMCITY,
                StationForm,
                m_lang.TOCITY,
                StationTo,
                m_lang.FIRM,
                Firm,
                m_lang.FLIGHTNO,
                FlightNo,
                m_lang.DEPARTDATE,
                Date,
                m_lang.PRICE,
                Price.ToString("#,##0"),
                m_lang.NAME,
                Name,
                m_lang.PHONE,
                Phone
                );
            nEnglish.Content = nViet.Description + string.Format("<div class='re-row'><p>{0}</p></div>", description);
            nEnglish.CreatedDate = DateTime.Now;
            nEnglish.UpdatedDate = DateTime.Now;
            nEnglish.Image = "/Content/Images/Site/logo.jpg";
            nEnglish.TypeID = 11;

            NewsBUS nBUS = new NewsBUS();
            nViet.LangID = 1;
            nEnglish.LangID = 2;
            nViet.IP = Request.UserHostAddress;
            nEnglish.IP = Request.UserHostAddress;
            if (nBUS.Insert(nViet, nEnglish))
            {
                m_Result.IsSuccess = 1;
                m_Result.ListMessage.Add(m_lang.SUCCESS);
            }
            else
            {
                m_Result.IsSuccess = -1;
                m_Result.ListMessage.Add(m_lang.NOTSUCCESS);
            }

            return View();
        }

    }
}
